#ifndef PID_CTRL_H
#define PID_CTRL_H


#define LIMIT_MIN_MAX(x,min,max) (x) = (((x)<=(min))?(min):(((x)>=(max))?(max):(x)))
/**
  * @struct pid_struct_t
  * @brief struct of pid parameters
  */
typedef struct _pid_struct_t
{
  float kp;         ///< Kp
  float ki;         ///< Ki
  float kd;         ///< Kd
  float i_max;      ///< limit maximum of absolute value of integral
  float out_max;    ///< limit maximum of absolute value of output
  float k_deadband; ///< set the deadband
  
  int deadband_zero_output;
  float err[2];     ///< error and last error

  float p_out;
  float i_out;
  float d_out;
}pid_struct_t;

extern const pid_struct_t _s_PID;
extern const pid_struct_t _cd_PID;
extern const pid_struct_t _cq_PID;


float pid_calc(pid_struct_t *pid, float ref, float cur);

#endif
